package com.example.shop_2208

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.webkit.WebChromeClient
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.core.view.isVisible
import com.example.shop_2208.databinding.ActivityWebViewBinding
import com.example.shop_2208.mvvm.BaseViewActivity

class WebViewActivity : BaseViewActivity<ActivityWebViewBinding>() {
    override fun initData() {

    }

    override fun initView() {
        val url:String = intent.getStringExtra("url").toString()//获取传递的网址
        binding.wv.loadUrl(url)//加载网址
        binding.wv.webViewClient = WebViewClient()//设置上后，会在APP内打开
        binding.wv.settings.javaScriptEnabled = true//网页上的事件可以点击
        val webChromeClient = object :WebChromeClient(){
            override fun onProgressChanged(view: WebView?, newProgress: Int) {
                super.onProgressChanged(view, newProgress)
                if(newProgress==100){
                    binding.pb.isVisible = false
                }
                binding.pb.progress = newProgress
            }
        }//加载进度条
        binding.wv.webChromeClient = webChromeClient
    }

    override fun getLayout(): Int = R.layout.activity_web_view

}